# -*- coding:utf-8 -*- #
import sys
import os

from twisted.internet.protocol import Protocol, Factory
from twisted.internet import reactor, defer
from twisted.internet.endpoints import TCP4ServerEndpoint

class GSProtocol(Protocol):
    def __init__(self):
        self.length = 0
        self.total = ''
        self.content = ''
        pass

    def dataReceived(self, data):
        print self.transport.client
        #self.transport.write('success')
        print data
        
        #d = defer.Deferred()
        #d.addCallback(self.process)
        #data = self.content
        #reactor.callLater(0, d.callback, data)
        #self.content = ''

    def connectionLost(self, reason):
        pass


def initial():
    #TODO:initial alarm data from redis

    factory = Factory()
    factory.protocol = GSProtocol
    endpoint = TCP4ServerEndpoint(reactor, 2000)
    endpoint.listen(factory)
    reactor.run()

if __name__ == '__main__':
    initial()
